package com.ry.copyOnWrite;

import java.util.concurrent.CopyOnWriteArraySet;

public class CopyOnWriteSetExp {

    private final CopyOnWriteArraySet<Handler> handlers = new CopyOnWriteArraySet<Handler>();

    public void addHandler(Handler h){ handlers.add(h); }

    private long internalState;

    private synchronized void changeState() { internalState = 1L; }

    public void update(){
        changeState();
        for (Handler handler : handlers)
            handler.doHandler();
    }

}


class Handler {
    void doHandler(){
        System.out.println("do something");
    }
}